import {ApiCodeEnum} from "../../enum/api-code.enum";

export class ResultVo{
    // 状态码
    code: number
    // 消息
    message: string
    // data数据
    data?: any
    // 成功
    static success(){
        let res = new ResultVo()
        res.code = 200
        res.message = "success"
        return res
    }
    //返回成功含有数据
    static successWithData(data: any){
        let res = new ResultVo()
        res.code = 200
        res.message = "success"
        res.data = data
        return res
    }
    // 失败
    static fail(msg: string){
        let res = new ResultVo()
        res.code = -1
        res.message = msg
        return res
    }
    // 失败
    static exception(apiCodeEnum: ApiCodeEnum){
        let e = apiCodeEnum.split(":")
        let res = new ResultVo()
        res.code = parseInt(e[0])
        res.message = e[1]
        return res
    }
}